package com.generator.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.generator.entity.TemplateGroup;
import com.generator.service.TemplateGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : zsljava
 * @date Date : 2020-12-15 9:51
 * @Description: TODO
 */
@RestController
@RequestMapping("/generator/templategroup")
public class TemplateGroupController {

    @Autowired
    private TemplateGroupService templateGroupService;

    /**
     * 查询所有记录
     *
     * @return 返回集合，没有返回空List
     */
    @RequestMapping("list")
    public ResponseEntity list(Page pageDto, TemplateGroup templateGroup) {
        return templateGroupService.list(pageDto, templateGroup);
    }


    /**
     * 根据主键查询
     *
     * @param id 主键
     * @return 返回记录，没有返回null
     */
    @RequestMapping("get/{id}")
    public ResponseEntity get(@PathVariable("id") int id) {
        TemplateGroup group = templateGroupService.getById(id);
        return ResponseEntity.ok(group);
    }

    /**
     * 新增，忽略null字段
     *
     * @param templateGroup 新增的记录
     * @return 返回影响行数
     */
    @PostMapping("save")
    public ResponseEntity insert(@RequestBody TemplateGroup templateGroup) {
        return templateGroupService.save(templateGroup);
    }


    /**
     * 删除记录
     *
     * @param  ids
     * @return 返回影响行数
     */
    @RequestMapping("del")
    public ResponseEntity del(@RequestBody List<Integer> ids) {
        templateGroupService.del(ids);
        return ResponseEntity.ok().build();
    }

}